home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 010a / dietdisc.zip / DIETINFO.C < prev    next >
C/C++ Source or Header  |  1991-02-10  |  6KB  |  248 lines

  1.  
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <fcntl.h>
  5. #include <io.h>
  6. #include <conio.h>
  7. #include <string.h>
  8. #include <dir.h>
  9. #include <stdlib.h>
  10.  
  11. char    *filefind(char *filepat);
  12. int     int24handler(int, int, int, int);
  13. void    display_stats(void);
  14. void    do_heading(void);
  15.  
  16. /***************************************************************/
  17.  
  18. int         firsttime;
  19. int         filehandle;
  20. int         filecount;
  21. int         linecount;
  22.  
  23. double      actual_size;
  24. double      pretend_size;
  25. double      total_actual;
  26. double      total_pretend;
  27. char        yes_no [4];
  28. double      percent;
  29.  
  30. char far    *olddta;
  31. char        drive[MAXDRIVE];
  32. char        dirs[MAXDIR];
  33. char        filename[MAXFILE];
  34. char        ext[MAXEXT];
  35. char        fullname[MAXPATH];
  36. char        filepat [MAXPATH];
  37. char        *foundname;
  38. char        *opt1;
  39. char        *opt2;
  40. char        *filename_ptr;
  41.  
  42. struct      ftime   ftimestruc;
  43. struct      ffblk   dos_find_blk;
  44.  
  45. unsigned    int useg;
  46. unsigned    int our_cs;
  47. char        *footprint;
  48. char        foottest[80];
  49.  
  50. unsigned int diet_cs = 0;
  51. int far     *diet_flag_ptr;
  52.  
  53. char    fs_loaded = 0;
  54. int     bytes;
  55.  
  56. struct  {
  57.         char  signature[6];
  58.         long  filesize;
  59.         char  filler[6];
  60.         }
  61.         ctlrec;
  62.  
  63. /***************************************************************/
  64.  
  65. void    main(int argc, char *argv[])
  66.         {
  67.         harderr(int24handler);
  68.         fs_loaded = 0;
  69.  
  70.         _AX = 0x3341;
  71.         geninterrupt(0x21);
  72.         if (_DX == 0x1234)
  73.             diet_cs = _CX;
  74.  
  75.         if (diet_cs != 0)
  76.             {
  77.             fs_loaded = 1;
  78.             diet_flag_ptr = MK_FP(diet_cs, 0x0103);
  79.             }
  80.  
  81.         if (argc == 2)
  82.             {
  83.             strcpy (filepat, argv[1]);
  84.             }
  85.         else
  86.             {
  87.             strcpy (filepat, "*.*");
  88.             }
  89.  
  90.  
  91.         filecount = 0;
  92.         linecount = 0;
  93.         fnsplit(filepat, drive, dirs, filename, ext);
  94.  
  95.         do_heading();
  96.  
  97.         while ( (foundname = filefind(filepat)) != NULL )
  98.             {
  99.             fnmerge(fullname, drive, dirs, foundname, NULL);
  100.             if ((filehandle = _open(fullname, O_RDWR)) == -1)
  101.                {
  102.                printf("Internal error; file not found.\n");
  103.                exit(1);
  104.                }
  105.  
  106.             actual_size  = (double) dos_find_blk.ff_fsize;
  107.  
  108.             if (fs_loaded)
  109.                 pretend_size = (double) filelength(filehandle);
  110.             else
  111.                 {
  112.                 bytes = read(filehandle, &ctlrec, 16);
  113.                 if (bytes != 16)
  114.                     pretend_size = actual_size;
  115.                 else
  116.                 if (memcmp(ctlrec.signature, "lZdIeT", 6) != 0)
  117.                     pretend_size = actual_size;
  118.                 else
  119.                     pretend_size = (double) ctlrec.filesize;
  120.                 }
  121.             filecount++;
  122.             display_stats();
  123.  
  124.             _close (filehandle);
  125.             }
  126.  
  127.         if (total_pretend == 0.0)
  128.            percent = 0.0;
  129.         else
  130.            percent = ((total_pretend - total_actual) / total_pretend) * 100.0;
  131.  
  132.         printf(
  133.         "%9.0lf bytes in %d files; %8.0lf bytes saved.  (%4.0lf%%)\n",
  134.         total_actual, filecount, total_pretend - total_actual, percent);
  135.         }
  136.  
  137. /***************************************************************/
  138.  
  139. void    display_stats(void)
  140.         {
  141.         if (linecount > 23)
  142.             {
  143.             linecount = 0;
  144.             printf("Press any key to continue the list....\n");
  145.             getch();
  146.             do_heading();
  147.             }
  148.  
  149.         if (pretend_size == 0.0)
  150.            percent = 0.0;
  151.         else
  152.            percent = ((pretend_size - actual_size) / pretend_size) * 100.0;
  153.  
  154.         if (actual_size == pretend_size)
  155.             strcpy(yes_no, " No");
  156.         else
  157.             strcpy(yes_no, "Yes");
  158.  
  159.         total_actual  += actual_size;
  160.         total_pretend += pretend_size;
  161.  
  162.         printf(
  163. "%-12s        %-3s      %8.0lf          %8.0lf         % 4.0lf%%\n",
  164. foundname, yes_no, actual_size, pretend_size, percent);
  165.         linecount++;
  166.  
  167.         }
  168.  
  169. /***************************************************************/
  170.  
  171. void    do_heading(void)
  172.         {
  173.         if (fs_loaded)
  174.             {
  175.             if (*diet_flag_ptr == 0)
  176.                 printf("Diet Disk is active.\n");
  177.             else
  178.                 printf("Diet Disk is loaded but not active.\n");
  179.             }
  180.         else
  181.             printf("Diet Disk is not loaded.\n");
  182.  
  183.         printf(
  184. "File              Skinny?     File Size       Unskinny Size      Percent\n");
  185.         printf(
  186. "-------------     -------     ---------       -------------      -------\n");
  187.         linecount += 3;
  188.         }
  189.  
  190. /***************************************************************/
  191.  
  192. char    *filefind(char *filepat)
  193.         {
  194.  
  195.         olddta = getdta();
  196.  
  197.         if (firsttime) goto getnextblk;
  198.  
  199.         firsttime = 1;
  200.         if (findfirst(filepat, (struct ffblk *) &dos_find_blk, 0) != 0)
  201.            {
  202.             setdta( (char far *) &olddta);
  203.             return(NULL);
  204.            }
  205.  
  206.         setdta( (char far *) &olddta);
  207.         return(dos_find_blk.ff_name);
  208.  
  209. getnextblk:
  210.         if (findnext( (struct ffblk *) &dos_find_blk) != 0)
  211.            {
  212.             setdta( (char far *) &olddta);
  213.             return(NULL);
  214.            }
  215.  
  216.         setdta( (char far *) &olddta);
  217.         return(dos_find_blk.ff_name);
  218.  
  219.         }
  220.  
  221. /***************************************************************/
  222.  
  223. int     int24handler(int errval, int ax, int bp, int si)
  224.  
  225.         {
  226.         char    msg[25];
  227.         int     drive;
  228.  
  229.         if (ax < 0)
  230.             {
  231.             bdosptr(0x09, "\nDevice I/O error has occurred.\n$", 0);
  232.             bdosptr(0x09, "Attempting to recover....\n$", 0);
  233.             hardretn(-1);
  234.             }
  235.  
  236.         drive = (ax & 0x00FF);
  237.         sprintf(msg, "I/O error on disk drive %c. \n$", 'A' + drive);
  238.         bdosptr(0x09, msg, 0);
  239.         bdosptr(0x09, "Attempting to recover....\n$", 0);
  240.         hardretn(-1);
  241.         }
  242.  
  243. /***************************************************************/
  244.  
  245.  
  246.  
  247.  
  248.